#include "Clock.h"

namespace Timing
{
	bool Clock::initialize()
	{
		bool b = (0 != QueryPerformanceFrequency(&timeFrecuency));
		if (!b)
			return false;
		return (0 != QueryPerformanceCounter(&lastStartTime));
	}

	bool Clock::shutdown()	{ return true; }

	void Clock::start()
	{
		QueryPerformanceCounter(&lastStartTime);
	}
	void Clock::stop()
	{
		LARGE_INTEGER delta;
		LARGE_INTEGER thisTime;
		QueryPerformanceCounter(&thisTime);
		delta.QuadPart = thisTime.QuadPart - lastStartTime.QuadPart;
		deltaTime = ((float)delta.QuadPart) / timeFrecuency.QuadPart;
		deltaLastLap.QuadPart = thisTime.QuadPart;
	}

	void Clock::lap()
	{
		stop();
		start();
	}

	float Clock::lastLapTime() const
	{
		return deltaTime;
	}

}